package com.prs.crm.action.official;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.official.DeptMailNum;
import com.prs.crm.service.official.DeptMailNumService;

public class DeptMailNumAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private DeptMailNum deptMailNum;
	private DeptMailNumService deptMailNumService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public DeptMailNum getDeptMailNum() {
		return deptMailNum;
	}
	public void setDeptMailNum(DeptMailNum deptMailNum) {
		this.deptMailNum = deptMailNum;
	}
	public DeptMailNumService getDeptMailNumService() {
		return deptMailNumService;
	}
	public void setDeptMailNumService(DeptMailNumService deptMailNumService) {
		this.deptMailNumService = deptMailNumService;
	}
	@Action("listDeptMailNum")
	public String listDeptMailNum(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(DeptMailNum.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getDeptMailNumService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editDeptMailNum")
	public String editDeptMailNum(){
		if (ids!=null) {
			this.deptMailNum=this.getDeptMailNumService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value = "saveDeptMailNum", results = {
			@Result(name = "success", type = "redirect", location = "listDeptMailNum"),
			@Result(name = "error", type = "chain", location = "editDeptMailNum") })
	public String saveDeptMailNum(){
		if (deptMailNum.getId()==null) {
			this.getDeptMailNumService().save(deptMailNum);
		}else{
			this.getDeptMailNumService().submit(deptMailNum);
		}
		return SUCCESS;
	}
	@Action(value = "removeDeptMailNum", results = {
			@Result(name = "success", type = "redirect", location = "listDeptMailNum"),
			@Result(name = "error", type = "chain", location = "listDeptMailNum") })
	public String removeDeptMailNum(){
		if (ids!=null) {
			this.deptMailNum=this.getDeptMailNumService().get(ids[0]);
		}
		this.getDeptMailNumService().batchRemove(ids);
		return SUCCESS;
	}
}
